<?php
/**
 *
 * 信息提交
 *
 * @version        2013年1月16日Z Yeshili
 * @author         叶世立 QQ：371773984
 */
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once('class.mail.php');
if(!isset($action))
{
    $action = '';
}
if($action=='send')
{
	if($yuyuan=="cn"){
		 $yanzheng="验证码错误！";
		 $shijian="管理员可以设置一个时间间隔,请稍等休息一下！";
		 $chenggong="信息提交成功,谢谢!";
		 $laiyuan="中文来源";
		 $error="出错啦";
		}else if($yuyuan=="en"){
		 $yanzheng="Verification code error！";
		 $shijian="Administrators to set a time interval, wait a minute, please have a rest！";
		 $chenggong="The information you submit success, thank you!";
		 $laiyuan="英文来源";
		 $error="Error!";
			}
    //检查验证码
    if(preg_match("/3/",$safe_gdopen)){
        $validate = isset($validate) ? strtolower(trim($validate)) : '';
        $svali = GetCkVdValue();
        if(strtolower($validate)!=$svali || $svali=='')
        {
            ResetVdValue();
            ShowMsg($yanzheng, '-1');
			$validate="";
            exit();
        }
        
    }

    //保存评论内容
    if($comtype == 'comments')
    {
		 //检查评论间隔时间
		$ip = GetIP();
		$dtime = time();
		$cfg_feedback_time=5;
		$prweb=$_SERVER[HTTP_REFERER];
		if(!empty($cfg_feedback_time))
		{
			//检查最后发表评论时间，如果未登陆判断当前IP最后评论时间
			$where = "WHERE `ip` = '$ip'";
			$row = $dsql->GetOne("SELECT dtime FROM `#@__message` $where ORDER BY `id` DESC ");
			if(is_array($row) && $dtime - $row['dtime'] < $cfg_feedback_time)
			{
				ResetVdValue();
				ShowMsg($shijian, '-1');
				exit();
			}
			else
			{
			 $query = "INSERT INTO #@__message(`laiyuan`,`username`,`sex`,`shouji`,`content`,`ip`,`dtime`) VALUES ('$laiyuan','$username','$sex','$shouji','$content','$ip','$dtime')";
			 if($dsql->ExecuteNoneQuery($query))
			 {	
			$MailBody="<table width=650 border=1 bordercolordark=#FFFFFF bordercolorlight=#CCCCCC cellpadding=0 cellspacing=0 style=word-break:break-all;word-wrap:break-word;><tr><td height=30 colspan=6 align=center><font style=font-size:16px;color:#BD0000;>".$cfg_webname."网站留言</font></td></tr><tr><td width=15% bgcolor=#F7F7F7 align=center>姓名</td><td width=15% ><font color=#BD0000>".$username."</font></td><td width=15% bgcolor=#F7F7F7 align=center>性别</td><td width=15% ><font color=#BD0000>".$sex."</font></td><td width=15% bgcolor=#F7F7F7 align=center>手机</td><td width=35%><font color=#BD0000>".$shouji."</font></td></tr><tr> <td width=15% bgcolor=#F7F7F7 align=center>留言时间</td> <td colspan=6>2013".date("y-m-h h:i:s")."</td></tr><tr>  <td bgcolor=#F7F7F7 align=center>来源ip</td>  <td colspan=6>".$ip."</td>  </tr><tr><td width=15% bgcolor=#F7F7F7 align=center>提交页面</td> <td colspan=6>".$prweb."</td>  </tr><tr><td width=15% bgcolor=#F7F7F7 align=center>来源网站</td> <td colspan=6><font color=#BD0000>".$laiyuan."</font></td>  </tr><tr> <td width=15% bgcolor=#F7F7F7 align=center>留言内容</td> <td colspan=6>".$content."</td></tr></table>";
			  //发送邮件
			  $MailServer = $cfg_smtp_server;      //SMTP 服务器
			  $MailPort   = $cfg_smtp_port;					 //SMTP服务器端口号 默认25
			  $MailId     = $cfg_smtp_user;  //服务器邮箱帐号
			  $MailPw     = $cfg_smtp_password;			     //服务器邮箱密码			  
			  /**
			  *客户端信息
			  */    			 
			  $email      = $cfg_smtp_usermail;//接收者邮箱
			  $Title = iconv("UTF-8","GB2312//IGNORE",$cfg_webname."-网站留言信息"); //邮件标题
			  $Content = iconv("UTF-8","GB2312//IGNORE",$MailBody);//邮件内容		  
			  $smtp = new smtp($MailServer,$MailPort,true,$MailId,$MailPw);
			  $smtp->debug = false;
			  if($smtp->sendmail($email,$MailId, $Title, $Content, "HTML")){
					ShowMsg($chenggong,$prweb);	
			  } else {
					 ShowMsg($error,'-1');         //$succeed = 0;
			  }	
			  
			  				 			 
			 }else
			 {
				 ShowMsg($error,'-1');
			  }
             
			}
		}
    }
}